package pe.edu.upc.dew.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


import pe.edu.upc.dew.model.Contacto;
import pe.edu.upc.dew.service.ContactoService;


@Controller
public class ContactoController {
    @Autowired
    private ContactoService contactoService;
    
    @RequestMapping(value = "/addcontactenos.htm", method = RequestMethod.POST)
    public String onSubmit(@ModelAttribute("contacto") Contacto contacto, BindingResult result) {
        System.out.println("onSubmit");
        System.out.println("contacto.getIdContacto() "+  contacto.getIdContacto());
        
        if (contacto.getIdContacto().equalsIgnoreCase("")) {
        	contactoService.agregar(contacto);
        }
        return "redirect:/contacto.htm";
    }    
}
